/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Database;

import java.sql.*;
import java.util.Vector;


public class Catalogue_Vender
{
    private int VenderId;
    private int CatalogueId;

    /**
     * @return the VenderId
     */
    public int getVenderId() {
        return VenderId;
    }

    /**
     * @param VenderId the VenderId to set
     */
    public void setVenderId(int VenderId) {
        this.VenderId = VenderId;
    }

    /**
     * @return the CatalogueId
     */
    public int getCatalogueId() {
        return CatalogueId;
    }

    /**
     * @param CatalogueId the CatalogueId to set
     */
    public void setCatalogueId(int CatalogueId) {
        this.CatalogueId = CatalogueId;
    }
    
    public boolean AddCV()
    {
        boolean kq = true;
        try
        {
            Connection con = ConecttoDatabase.getConnection();
            String query = "insert into Catalogue_Vender values(?, ?)";
            PreparedStatement ps = con.prepareStatement(query);
            ps.setInt(1,this.VenderId);
            ps.setInt(2,this.CatalogueId);
            
            kq = ps.executeUpdate() > 0;
        }
        catch(Exception ex)
        {
            System.out.println(ex);
            kq = false;
        }
        return kq;
    }
    
    public boolean EditCV()
    {
        boolean kq = true;
        try 
        {
            Connection con = ConecttoDatabase.getConnection();
            String query = "update Catalogue_Vender set VenderId='"+this.VenderId+"' where CatalogueId='"+CatalogueId+"'";
            Statement st = con.createStatement();
            kq = st.executeUpdate(query)>0;
        }
        catch (Exception e)
        {
            kq=false;
            System.out.println(e);
        }
        return kq;
    }
    
    public  boolean  DelCV()
    {
        boolean kq = true;
        try 
        {
            Connection con = ConecttoDatabase.getConnection();
            String query = "delete from Catalogue_Vender set CatalogueId='"+this.CatalogueId+"'";
            PreparedStatement ps =con.prepareStatement(query);
            kq = ps.executeUpdate()>0;
        }
        catch (Exception e) {
        kq = false;
            System.out.println(e);
        }
        return kq;
    }
    

     
     public Vector<Catalogue_Vender> Cat_VenInfomation()
     {
         Vector<Catalogue_Vender> catven = new Vector<Catalogue_Vender>();
         try 
         {
             Connection con = ConecttoDatabase.getConnection();
             String query = "select * from Catalogue_Vender";
             Statement st = con.createStatement();
             ResultSet rs = st.executeQuery(query);
             while (rs.next())
             {                 
                 Catalogue_Vender cave = new Catalogue_Vender();
                 cave.setCatalogueId(rs.getInt("CatalogueId"));
                 cave.setVenderId(rs.getInt("VenderId"));
                 catven.add(cave);
             }
         } 
         catch (Exception e) 
         {
             catven=null;
             System.out.println(e);
         }
         
         return catven;
     }
    
     public  static Vender LayGiaTri(String VenderId)
     {
         Vender vdd = new Vender();
         try 
         {
             Connection con = ConecttoDatabase.getConnection();
             String query ="select * from Vender where VenderId=?";
             Statement st = con.createStatement();
             ResultSet rs = st.executeQuery(query);
             while (rs.next())
             {                 
                 vdd.setVenderId(rs.getInt("VenderId"));
                 vdd.setVenderName(rs.getString("VenderName"));
                 vdd.setAddress(rs.getString("Address"));
                 vdd.setEmail(rs.getString("Email"));
                 vdd.setPhone(rs.getString("Phone"));
             }
         } 
         catch (Exception e) 
         {
             vdd = null;
             System.out.println(e);
         }
         return vdd;
     }
     
         public static Catalogue_Vender infomationCV(String VenderId) 
         {
        Catalogue_Vender cv = new Catalogue_Vender();
        try 
        {
            Connection con = ConecttoDatabase.getConnection();
            String query = "Select * from Catalogue_Vender where VenderId=?";
            PreparedStatement ps = con.prepareStatement(query);
            ps.setString(1, VenderId);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                cv.setVenderId(rs.getInt("VenderId"));
                cv.setCatalogueId(rs.getInt("CatalogueId"));
            }
        } catch (Exception ex) 
        {
            cv = null;
            System.out.println(ex);
        }
        return cv;
    }
     
}
